// =============================================================
// CCubeScript
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Jul. 10, 2006
//----------------------------------------------------------------------
#include "CCubeScript.h"
//----------------------------------------------------------------------
CCubeScript::CCubeScript() : CScript()
{
	// -----------------------------------------
	// set internal variables by default
	// -----------------------------------------
	// environments ----------------------------
	string cube_path = "/cube";
	default_params["@cube"] = getMasterCubePath(cube_path);
	default_params["@cube_base"] = "${cube}/base";
	default_params["@local_dataset"] = "${cube_base}/dataset";
	default_params["@local_resultset"] = "${cube_base}/resultset";

	string cube_num = "cube num";
	string cube_list = "cube list";
	//default_params["@num_of_cubes"] = getAllNumberOfCubes(cube_num);
	//default_params["@available_cubes"] = getAvailableCubes(cube_list); 


	// parallelization -------------------------
	default_params["@dynamic_parameters_set"] = "";
	default_params["@cube_dynamic_param_pattern"] = "__cube_dynamic_param_pattern__";
	default_params["@dynamic_parameters"] = "${cube_dynamic_param_pattern}";


	// distribution ----------------------------
	default_params["@partitioning_type"] = "FILE";
	default_params["@partitioning_method"] = "RANDOM";
}
//----------------------------------------------------------------------
CCubeScript::~CCubeScript()
{
}
//----------------------------------------------------------------------
string &CCubeScript::getMasterCubePath(string &cube_path)
{
	char *pbuf = (char *)malloc(1024);
	pbuf = getcwd(pbuf, 1024);

	if(pbuf==NULL) {
		cout << "//////////////////////////////////////////////////" << endl;
		cout << "getMasterCubePath() error" << endl;
		cout << "//////////////////////////////////////////////////" << endl;
	}

	cube_path = pbuf;

	free(pbuf);

	return cube_path;
}
//----------------------------------------------------------------------
string &CCubeScript::getAllNumberOfCubes(string &cube_num)
{
	string command = "cluster | awk '{ print NF-1; }'";
	string result = executeShellCommand(command);
	cube_num = result;

	return cube_num;
}
//----------------------------------------------------------------------
string &CCubeScript::getAvailableCubes(string &cube_list)
{
	string command = "cluster | awk '{ for(i=2;i<=NF;i++) print $i; }' | xargs";
	string result = executeShellCommand(command);
	cube_list = result;

	return cube_list;
}
//----------------------------------------------------------------------
